define(['jquery', 'bootstrap', 'backend', 'table', 'form','upload'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/githouse/index',
                    add_url: 'store/githouse/add',
                    edit_url: 'store/githouse/edit',
                    del_url: 'store/githouse/del',
                    multi_url: 'store/githouse/multi',
                    table: 'githouse',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {field: 'gname', title: __('Gname')},
                        {field: 'dep', title: __('Ssgs_id')},
                        {field: 'address', title: __('Addrss')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'manger', title: __('Manger')},
                        {
                            field: 'name',
                            title: __('Name'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [],
                            formatter: Controller.api.formatter.view

                        }
                    ]
                ]
            });
            Table.api.bindevent(table);

            $(document).on("click",".mini",function () {
                var _this = $(this);
                console.log(_this);
                var ids = _this.attr("id");
                require(["upload"],function (Upload) {
                    Upload.api.plupload($("#"+ids+""));
                })
            });
            // 为表格绑定事件
        },
        add: function () {

            Controller.api.bindevent();
        },
        edit: function () {

            Controller.api.bindevent();
        },
        init:function(){


        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                browser: function (value, row, index) {
                    //这里我们直接使用row的数据
                    return '<a class="btn btn-xs btn-browser" href="http://www.baidu.com">1111</a>';
                },
                view: function (value, row, index) {
                    var table = this.table;
                    // 默认按钮组
                    var buttons = [];
                    buttons.push({
                        name: 'detail',
                        title: "",
                        text: "",
                        classname: 'btn btn-xs btn-success btn-editone',
                        icon: 'fa  fa-pencil',
                        extend: 'data-toggle="tooltip"',
                        url: 'store/githouse/edit'
                    });
                    buttons.push({
                        name: '删除',
                        title: "",
                        text: "",
                        classname: 'btn btn-xs btn-danger btn-delone',
                        icon: 'fa fa-trash',
                        extend: 'data-toggle="tooltip"',
                        url: 'store/githouse/del'
                    });
                    buttons.push({
                        name: '初始化',
                        title: "",
                        text: "初始化",
                        classname: 'btn btn-xs btn-danger btn-import mini btn-click',
                        icon: 'fa fa-upload',
                        extend: 'id="init'+row.id+'"  data-url="/admin/store/githouse/init?id='+row.id+'" data-mimetype="csv,xls,xlsx" data-multiple="false"',

                    });
                    return Table.api.buttonlink(this, buttons, value, row, index, 'buttons');
                },
                del: function (value, row, index) {
                    var table = this.table;

                },

            }
        }
    };
    return Controller;ƒ
});
